<?php
/**
 * 处理swoole服务端回调数据处理
 */
namespace Home\Controller;
use Think\Controller;
class SwooleTestController extends Controller {
    public function index(){
        echo "hello world";
    }

    /**
     * @param $game     小程序
     * @param $action   操作行为
     * @param $test     是否是测试用
     * @param call_back 回调链接
     */
    public function api_accept()
    {
        $game       =   I('post.game','','htmlspecialchars');
        $action     =   I('post.action','','htmlspecialchars');
        $test       =   I('post.test','','htmlspecialchars');
        $call_back  =   I('post.call_back','','htmlspecialchars');
        $table      =   I('post.table','','htmlspecialchars');

        if(! empty($game) && ! empty($action) && ! empty($call_back) && ! empty($table))
        {

        }

        if (! empty($_POST))
        {
            $insert['log']          =   json_encode($_POST);
            $insert['create_time']  =   time();
            $result = M('swoole_message')->add($insert);

            $msg['state']   =   1;
            $msg['error']   =   '接受成功';
            $this->ajaxReturn ($msg,'JSON');
        }

        echo 'welcome SwooleTest';
    }

    public function callback()
    {
        if (! empty($_POST))
        {
            $insert['log']          =   json_encode($_POST);
            $insert['create_time']  =   time();
            M('swoole_callback')->add($insert);
        }
        echo 'welcome callback';
    }
}